package com.dgut.service.background.dao;

import com.dgut.service.background.entity.Enter;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EnterDao extends JpaRepository<Enter, Integer>, PagingAndSortingRepository<Enter, Integer> {
    Page<Enter> findAllByTimesBetween(String date1, String date2, Pageable pageable);

    Page<Enter> findAllByUserOpenidLike(String userOpenid, Pageable pageable);

    @Query("select new Enter(e.enterId,e.inspectorOpenid,e.userOpenid,e.health,e.times,e.temp) from Enter e,User u where u.name = :username and e.userOpenid = u.openid")
    Page<Enter> findAllByUsername(@Param("username") String username, Pageable pageable);

    Page<Enter> findAllByTimesBetweenAndUserOpenidLike(String date1, String date2, String userOpenid, Pageable pageable);

    @Query("select new Enter(e.enterId,e.inspectorOpenid,e.userOpenid,e.health,e.times,e.temp) from Enter e,User u where u.name = :username and e.userOpenid = u.openid and e.times between :date1 and :date2")
    Page<Enter> findAllByTimesBetweenAndUsernameLike(@Param("date1") String date1, @Param("date2") String date2, @Param("username")String userOpenid, Pageable pageable);

    List<Enter> findAllByTimesBetween(String date1,String date2);

    List<Enter> findAllByUserOpenidLike(String userOpenid);

    @Query("select new Enter(e.enterId,e.inspectorOpenid,e.userOpenid,e.health,e.times,e.temp) from Enter e,User u where u.name = :username and e.userOpenid = u.openid")
    List<Enter> findAllByUsername(@Param("username") String username);

    List<Enter> findAllByTimesBetweenAndUserOpenidLike(String date1, String date2, String userOpenid);

    @Query("select new Enter(e.enterId,e.inspectorOpenid,e.userOpenid,e.health,e.times,e.temp) from Enter e,User u where u.name = :username and e.userOpenid = u.openid and e.times between :date1 and :date2")
    List<Enter> findAllByTimesBetweenAndUsernameLike(@Param("date1") String date1, @Param("date2") String date2, @Param("username") String username);

    List<Enter> findAllByHealth(String health);

    List<Enter> findAllByTempLessThan(double temp);

    List<Enter> findAllByTempGreaterThan(double temp);

    List<Enter> findAllByTempBetween(double temp1, double temp2);

    List<Enter> findAll();
}
